package top.drinyeit.weilong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import top.drinyeit.weilong.R;
import top.drinyeit.weilong.model.BalanceDetailBean;

/**
 * Created by bigHead on 2017/11/21.
 */

public class PaymentDetailsAdapter extends BaseAdapter{
    private Context context;
    private List<BalanceDetailBean> list;
    private LayoutInflater mInflater;

    public PaymentDetailsAdapter (Context context,List<BalanceDetailBean> list){
        this.context = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null){
            viewHolder = new ViewHolder();
            view = mInflater.inflate(R.layout.item_pay_details,null);
            viewHolder.way = view.findViewById(R.id.way);
            viewHolder.date = view.findViewById(R.id.date);
            viewHolder.balance = view.findViewById(R.id.balance);
            viewHolder.add = view.findViewById(R.id.add);

            view.setTag(viewHolder);
        }else {
            viewHolder=(ViewHolder) view.getTag();
        }
        viewHolder.way.setText(list.get(i).getDescription());
        viewHolder.date.setText(list.get(i).getCreate_time());
        viewHolder.balance.setText("余额:" + list.get(i).getCurrent_balance());
        viewHolder.add.setText((list.get(i).getType() == 1? "+" : "-") + list.get(i).getAmount());

        return view;
    }

    private class ViewHolder{
        TextView way;
        TextView date;
        TextView balance;
        TextView add;
    }
}
